﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace networkTestUtilities
{
    public class Generator
    {
        public Boolean run = false;
        public DataPusher target;

        public int waitPeriod = 1000;
        public int numSensors;

        DateTime unixRef = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        public void start()
        {
            run = true;
            System.Threading.Thread t = new System.Threading.Thread(runThread);
            t.Start();
        }

        private void runThread()
        {
            while (run)
            {
                long timeStamp = ((DateTime.Now.ToUniversalTime().Ticks - unixRef.Ticks) / 10000);

                for(int i =0; i < numSensors; i++)
                {
                    float testValue = (float) (10 * Math.Sin(timeStamp / 1000 / 1.591) + 5 + i);
                    target.addDataPoint(i, testValue, timeStamp);
                }
                System.Threading.Thread.Sleep(waitPeriod);
            }
        }

        public void pulse()
        {
            long timeStamp = ((DateTime.Now.ToUniversalTime().Ticks - unixRef.Ticks) / 10000);

            for (int i = 0; i < numSensors; i++)
            {
                float testValue = (float)(10 * Math.Sin(timeStamp / 1000 / 1.591) + 5 + i);
                target.addDataPoint(i, testValue, timeStamp);
            }
        }
    }
}
